package splash;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class SplashView extends SurfaceView implements SurfaceHolder.Callback {
	private SplashThread mSplashThread;
	private SurfaceHolder msSurfaceHolder;
	private Context mcContext;

	public SplashView(Context context, AttributeSet attrs) {
		super(context, attrs);
		mcContext = context;
		msSurfaceHolder = getHolder();
		msSurfaceHolder.addCallback(this);
		mSplashThread = new SplashThread(this, mcContext);
		setFocusable(true);
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		mSplashThread.doTouch(event);
		this.surfaceDestroyed(getHolder());
		return super.onTouchEvent(event);
	}

	public void surfaceCreated(SurfaceHolder holder) {
		mSplashThread.setRunning(true);
		mSplashThread.start();
	
	}

	public void surfaceDestroyed(SurfaceHolder holder) {
		boolean retry = true;
		mSplashThread.setRunning(false);
		while (retry) {
			try {
				mSplashThread.join();
				retry = false;
			} catch (InterruptedException e) {
			}
		}
	}

	public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
		// TODO Auto-generated method stub

	}

}
